package main

import (
	"fmt"
)

// 数组
func ForArr() {
	arr := [3]int{1, 2, 3}
	for index, value := range arr {
		println("下标为", index, "值为", value)
	}
}

// 切片
func ForSlice() {
	slice := []int{1, 2, 3}
	for index, value := range slice {
		println("下标为", index, "值为", value)
	}
}

// 字典 map
func ForMap() { //map range 是无序的
	m := map[string]int{
		"foo": 1,
		"bar": 2,
		"baz": 3,
	}
	for k, v := range m {
		println(k, v)
	}

}

func LoopBug() {
	users := []User{
		{
			name: "daming",
		},
		{
			name: "xiaoming",
		},
	}

	m := make(map[string]*User)
	for _, user := range users {
		m[user.name] = &user //取地址
		fmt.Print("\n", m)
	}

}

type User struct {
	name string
}

func LoopBreak() {
	i := 0
	for true {
		if i >= 10 {
			break
		}
		println(i)
		i++
	}
}
func LoopContinue() {

	for i := 1; i < 10; i++ {
		if i%2 == 1 {
			continue

		}
		println(i)

	}

}
